<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />

<html>
<head>
<script type="text/javascript" src="${ctx}/static/jquery/jquery-1.8.3.js"></script>
<script language="javascript" src="${ctx}/static/LodopFuncs.js"></script>
<script type="text/javascript" src="${ctx}/static/print.js"></script>
<script>
var LODOP;
function createPrinterList(){
    if (document.getElementById('PrinterList').innerHTML!="") return;
	LODOP=getLodop(); 
	var iPrinterCount=LODOP.GET_PRINTER_COUNT();
	for(var i=0;i<iPrinterCount;i++){
		var option=document.createElement('option');
		option.innerHTML=LODOP.GET_PRINTER_NAME(i);
		option.value=i;
		option.setAttribute("title",LODOP.GET_PRINTER_NAME(i));
		document.getElementById('PrinterList').appendChild(option);
	}	
}
function getSelectedPrintIndex(){
	if (document.getElementById('printer').checked) 
	return document.getElementById('PrinterList').value;
	else return -1; 		
}
function clearPageListChild(){
	   var PagSizeList = document.getElementById('PagSizeList'); 
	   while(PagSizeList.childNodes.length>0){
		   var children = PagSizeList.childNodes;	
	  		for(i=0;i<children.length;i++){		
				PagSizeList.removeChild(children[i]);	
	  	    }	   
	   }	   
}
function createPagSizeList(){
	   LODOP=getLodop(); 
	   clearPageListChild();
	   var strPageSizeList=LODOP.GET_PAGESIZES_LIST(getSelectedPrintIndex(),"\n");
	   var Options=new Array(); 
	   Options=strPageSizeList.split("\n");       
	   for(i in Options)    
	   {    
	     var option=document.createElement('option');   
		 option.innerHTML=Options[i];
		 option.value=Options[i];
		 option.setAttribute("title",Options[i]);
		 document.getElementById('PagSizeList').appendChild(option);
	   }  
}
var result='${result}';
var jsonObj = $.parseJSON(result);
var userId = jsonObj.userId;
var printReportIds = jsonObj.printReportIds;
$(function(){
	$("#batchPrint").click(function(){
		for(var i=0;i<printReportIds.length;i++){
			var reportId = printReportIds[i];
			$.ajax({
				type:'POST',
				url:"${ctx}/reports/service.do?method=showReportInfo&reportOperatorId="+userId+"&reportId="+reportId,
				dataType:'html',
				cache:false,
				success:function(data){
					print(true,data);
				},
				error:function(XMLHttpRequest, textStatus, errorThrown){
					alert(XMLHttpRequest.status);
                    alert(XMLHttpRequest.readyState);
                    alert(textStatus);
				}

			});
		}		
	});
	$("#defaultPrinter").click(function(){
		$("#PrinterList").empty();
	});
	$("#defaultPageType").click(function(){
		$("#PagSizeList").empty();
	});
});
</script>
</head>
<body>
打印纸张宽度：<input id="pageWidth" type="text">
打印纸张高度：<input id="pageHeight" type="text"><p>
<span style="width:104px;">打印方向：</span>
<select id="orient" style="width:155px;">
	<option value="">请选择</option>
	<option value="1">纵向</option>
	<option value="2">横向</option>
</select>
<input type="radio" id="defaultPrinter" name="printer" checked >默认打印机
<input type="radio" id="printer" name="printer" onclick="createPrinterList()">指定打印机                 
<select id="PrinterList" style="width:155px;"></select><p>
<input type="radio" id="defaultPageType" name="pageType" checked>不指定纸张                         
<input type="radio" id="pageType" name="pageType" onclick="createPagSizeList()">指定纸张
<select id="PagSizeList" style="width:155px;"></select><p>
<input type="button" id="batchPrint" value="批量打印">
</body>
</html>
